#ifndef HELPER_H
#define HELPER_H

#include <QString>
#include <QByteArray>
#include <QDebug>
#include <QProcess>
#include <QTextCodec>
#include <QDateTime>
#include <QFile>
#include <QDataStream>
#include <QNetworkInterface>
#include <QHostAddress>
#include <QDir>
#include <QFile>
#include <QFileInfo>

#define BASE_FILE           "/etc/hostname"

#define SET_BIT(x, bit)     (x |= (1 << bit))           /// 置位第bit位
#define GET_BIT(x, bit)     ((x & (1<<bit)) >> bit)     /// 获取第bit位
#define CLEAR_BIT(x, bit)   (x &= ~(1<<bit))             /// 清零第bit位

#define GET_LOW_BYTE0(x)    ((x >> 0) & 0x000000ff)     /// 取第0个字节
#define GET_LOW_BYTE1(x)    ((x >> 8) & 0x000000ff)     /// 取第1个字节
#define GET_LOW_BYTE2(x)    ((x >> 16) & 0x000000ff)    /// 取第2个字节
#define GET_LOW_BYTE3(x)    ((x >> 14) & 0x000000ff)    /// 取第3个字节

#define CLEAR_LOW_BYTE0(x)  (x &= 0xffffff00)           /// 清零第0个字节
#define CLEAR_LOW_BYTE1(x)  (x &= 0xffff00ff)           /// 清零第1个字节
#define CLEAR_LOW_BYTE2(x)  (x &= 0xff00ffff)           /// 清零第2个字节
#define CLEAR_LOW_BYTE3(x)  (x &= 0x00ffffff)           /// 清零第3个字节

QString getLocalIP();

QString fillWithZero(const QString& src, int length);
QString getAppId(QString netId, int stationId, QString laneId);

void getLedBoardBytes(QString& text, QByteArray &outArr);
void encodeutf82gb2312(QString str, QByteArray &outArr);
void convertUTF8ToGB2312_16(char *str, quint8 strLen, QByteArray &outArr);
void convertUTF8ToGB2312(char *str, quint8 strLen, QByteArray &outArr);

QString executeLinuxCmd(QString strCmd);
unsigned int ip2int(QString ip);
QString int2ip(unsigned int ip);
QString byteArrayToHexStr(const QByteArray &data);
QByteArray hexStrToByteArray(const QString &str);
char convertHexChar(char ch);

quint8 XOR_Cal(unsigned char *data, unsigned int len);
quint8 sumData(QByteArray &data);

QString genMsgId(QString appId);

int bcd2decimal(int bcd);
int decimal2bcd(int decimal);

quint32 get_BE32(const QByteArray &data);
quint32 get_LE32(const QByteArray &data);

void RemovePlateSpecChar(char *vehPlate, size_t vehLen, const char *sVlpText, int vlpLen);

QString GB2312toUnicode(const char *gb2312String);
QByteArray UnicodetoGB2312(QString unicodeString);
QString UTF82GBK(QByteArray &inStr);
QString GBKtoUTF8(QByteArray &inStr);

bool WriteToFile(const QString &sFileName, char *lpBuffer, quint32 nBufferLen);
bool WriteBufToFile(const char *pszImageName, quint8 *pcBuffer, unsigned nBufferLen);

quint8 hex2ascii(quint8 hex);
void u8Hex2ascii(quint8 hex, quint8 *ascii_buff);
void u16Hex2ascii(quint16 hex, quint8 *ascii_buff);
quint8 ascii2hex(quint8 ascii);

void BCC_Cal(QByteArray &data, quint8 *ascii_buff);

bool RemoveFile(const QString &strFile);

QString convertMsToFormat(long ms);

#endif // HELPER_H
